package test;

import java.util.Timer;
import java.util.TimerTask;


public class monitorthreadV10 implements Runnable {



	private String command;
	int p;


	public  monitorthreadV10(String s){
		this.command=s;

	}

	private void processCommand() {

	
		Runtime.getRuntime().addShutdownHook(new Thread() {

			@Override
			public void run() {

				System.out.println("Thread shutdown");
				//executor.shutdown();
				// place your code here
			}

		});


		try {
			
			System.out.println("Waiting for program to finish ...");
			p = Runtime.getRuntime().exec(command).waitFor();
			//p.waitFor();


			System.out.println(p);
			
	/**		
			if (p.exitValue() == 0) {
				System.out.println("Finished correctly");
			} else {
				System.out.println("Failed");
			}
**/
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			System.out.println("Finally thread finished");
		}




	}

	@Override
	public void run() {
		processCommand();



	


}
	
}